import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import javax.imageio.ImageIO;

import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;

import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.audio.AudioHeader;
import org.jaudiotagger.audio.exceptions.CannotReadException;
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
import org.jaudiotagger.audio.mp3.MP3AudioHeader;
import org.jaudiotagger.audio.mp3.MP3File;
import org.jaudiotagger.tag.*;
import org.jaudiotagger.tag.datatype.Artwork;
import org.jaudiotagger.tag.id3.AbstractID3v2Tag;
import org.jaudiotagger.tag.id3.ID3v24Frames;
import org.jaudiotagger.tag.id3.ID3v24Tag;


public class Test {

	/**
	 * @param args
	 * @throws InvalidAudioFrameException 
	 * @throws ReadOnlyFileException 
	 * @throws TagException 
	 * @throws IOException 
	 * @throws CannotReadException 
	 * @throws JavaLayerException 
	 */
	public static void main(String[] args) throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException, JavaLayerException {
		File file = new File("testdaten/horizon.mp3");
		MP3File f = (MP3File)AudioFileIO.read(file);
		AbstractID3v2Tag v2 = f.getID3v2Tag();
		List<Artwork> artlst = v2.getArtworkList();
		Artwork art = artlst.get(0);
		BufferedImage img = art.getImage();
		ImageIO.write(img, "png", new File("thumb.png"));
		MP3AudioHeader ah = f.getMP3AudioHeader();
//		out(v2.getFirst(ID3v24Frames.FRAME_ID_ARTIST));
//		out(v2.getFirst(ID3v24Frames.FRAME_ID_ALBUM)); 
//		out(v2.getFirst(ID3v24Frames.FRAME_ID_COMMENT));
//		out(v2.getFirst(ID3v24Frames.FRAME_ID_LENGTH)); 
//		out(ah.isCopyrighted());
//		out(ah.getBitRate());
//		out(ah.getMpegLayer());
//		out(ah.getMpegVersion());
//		out(ah.getFormat());
//		out(ah.getTrackLength());
//		out(ah.getSampleRate());
//		out(ah.getEncoder());
//		out(f.hasID3v2Tag());
//		out(f.hasID3v1Tag());
//		out(f.displayStructureAsPlainText());
//		out(v2.getFirst(ID3v24Frames.FRAME_ID_ATTACHED_PICTURE));
//		Player mp3 = new Player(new FileInputStream("testdaten/itsashame.mp3"));
//		mp3.play();
	}

	private static void out(Object obj) {
		System.out.println(obj);
		
	}

}
